Skip to content

fix(ingestion): do not overwrite approved observations by default - #854

Merged
jirhiker merged 1 commit into
stagingfrom
fix/protect-approved-observations
Aug 19, 2026
Merged

fix(ingestion): do not overwrite approved observations by default#854
jirhiker merged 1 commit into
stagingfrom
fix/protect-approved-observations

Conversation

@jirhiker

Copy link
Copy Markdown
Member

Querying production for existing San Acacia data turned up something the plan
assumed away: 14 of the 38 wells already hold 542,161 observations, from the
AMPAPI transfer, running 2016-07-08 to 2022-08-03. They carry a real QC status,
so data_maturity backfilled them as approved.

The bug

The upsert was DO UPDATE SET value = excluded.value, data_maturity = excluded.data_maturity, with provisional as the default maturity.

A Mode A backfill over 2016–2022 would therefore have replaced 542,161
Bureau-approved values with vendor readings and downgraded them to
provisional
— silently, reporting success.

DO UPDATE exists so a vendor correction can revise our own provisional
readings. Applying it to reviewed history from another source is a different
act, and it should be one somebody chooses.

The fix

overwrite_approved defaults to False, and the conflict clause skips rows
whose maturity is approved. Passing True says the incoming data is better
than what was reviewed — a judgement for a person.

Rows with NULL maturity still update: IS DISTINCT FROM rather than !=.
Unknown is not approved, and treating it as such would freeze the 394,086 legacy
rows with no QC record against every future correction.

Three tests: approved rows survive, overwrite_approved=True gets through, NULL
rows still update.

Still owed before loading historical windows

Those AMPAPI rows were loaded under whatever datum that pipeline used; ours are
Diver-HUB ground-surface centimetres converted to feet. A few coinciding
timestamps should be compared before any window covering 2016–2022 is loaded.

Same failure shape as the WaterLevelReference question — plausible numbers,
wrong meaning.

Context recorded in the plan

The wider table: 2,180,989 approved, 7,351 provisional, 394,086 NULL. That NULL
cohort is 176 deployments on a single parameter spanning 2016 to February 2025
with no AMPAPI provenance — a separate network, and none of the 38 San Acacia
wells are in it
. Worth identifying independently of this work.

Also: the watermark now starts at 2022-08-03 for those 14 wells rather than the
2015 floor, so a normal run fetches a four-year gap rather than a decade.

🤖 Generated with Claude Code

Ocotillo already holds 542,161 approved observations for 14 of the 38 San Acacia
wells, from the AMPAPI transfer and running to August 2022. The upsert would
have replaced every one of them with a vendor reading and downgraded it to
provisional, silently, on any backfill covering that window.

DO UPDATE exists so a vendor correction can revise our own provisional
readings. Applying it to reviewed history from another source is a different
act, and it should be one somebody chooses: overwrite_approved defaults to
False and the conflict clause skips approved rows.

Rows with NULL maturity still update. Unknown is not approved, and treating it
as such would freeze the 394,086 legacy rows with no QC record against every
future correction.

Still owed: those AMPAPI rows were loaded under whatever datum that pipeline
used, and ours are ground-surface centimetres converted to feet. Overlapping
timestamps should be compared before any window covering 2016-2022 is loaded.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Coverage

79.33% total — gate is 75%.

Coverage for the Python files changed in this PR
Name Stmts Miss Cover Missing
automated_ingestion/ocotillo/loader.py 57 13 77% 60, 187-216
TOTAL 57 13 77%

@github-actions

github-actions Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Your pull request is automatically being deployed to Dagster Cloud.

Location Status Link Updated
ocotillo-automated-ingestion View in Cloud Aug 19, 2026 at 05:12 PM (UTC)

@jirhiker
jirhiker merged commit b522052 into staging Aug 19, 2026
10 checks passed
@jirhiker
jirhiker deleted the fix/protect-approved-observations branch August 19, 2026 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant